#include "BasicFunction.h"
#include <iostream>
#include <string>

#define _CRT_SECURE_NO_WARNINGS 1

// Compile: g++ -o3 main.cpp -o main.exe

int main(int argc, char *argv[])
{
	int img_choose;
	std::cout << "Please select the picture you want to modify:\n"
				 "1) 1.bmp (8 bit grey image)\n"
				 "2) b.bmp (8 bit color image)\n"
				 "3) hometown.bmp (24 bit color image)\n\n";

	std::cin >> img_choose;

	HXLBMPFILE bmpfile;
	int i, j;
	std::string image{"./image/"};
	switch (img_choose)
	{
	case 1:
		image += "1.bmp";
		break;
	case 2:
		image += "b.bmp";
		break;
	case 3:
	default:
		image += "hometown.bmp";
		break;
	}
	if (!bmpfile.LoadBMPFILE(image.c_str())) // 载入bmp图像
		exit(1);							 // 不成功则退出

	HXLBMPFILE bf; //建立输出bmp对象
	bf.imagew = bmpfile.imagew;
	bf.imageh = bmpfile.imageh;
	bf.iYRGBnum = bmpfile.iYRGBnum;
	if (bf.iYRGBnum == 1)
	{
		*bf.palette = *bmpfile.palette; // 对灰度图需复制调色板
	}
	if (!bf.AllocateMem())
		return 1;

	std::cout << "\n\nPlease choose the action you want to proceed:\n"
				 "1) Reverse color\n";
	int action_choose;
	switch (img_choose)
	{
	case 1:
	case 2:
		printf("2) Adjust palette\n\n");
		break;

	case 3:
		printf("2) Color to grey\n\n");
	}

	std::cin >> action_choose;
	switch (action_choose)
	{
	case 1:
		Reverse(bmpfile, bf);
		break;
	case 2:
	{
		if (img_choose == 1 || img_choose == 2)
		{
			AdjustPalette(bmpfile, bf);
			break;
		}
		else
		{
			ClrToGray(bmpfile, bf);
			break;
		}
	}
	}

	bf.SaveBMPFILE("result.bmp");
	printf("program ends!\n");

	// if (!bmp2txt(bmpfile))
	//	printf("Error\n");
	return 0;
}